public class MyQueue {

    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode first = null ;
    public ListNode last = null;

    public int usedsize = 0;

    public void offer(int val){
        ListNode node = new ListNode(val);
        if(first == null){
            first = last =node;
        } else {
            last.next = node;
            node.prev = last;
            last = last.next;
        }
        usedsize++;
    }
    public int poll(){
        if(isEmpty()){
            return -1;
        }
        if(first.next == null){
            int ret = first.val;
            last = first = null;
            usedsize--;
            return ret;
        }
        int ret = first.val;
        first.next.prev = null;
        first = first.next;
        usedsize--;
        return ret;
    }
    public int peek(){
        return first.val;
    }
    public boolean isEmpty(){
        return first == null;
    }

}
